﻿using Medart.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Medart.Controllers
{
    public class CustomersController : Controller
    {
        //
        // GET: /Customers/
        private HMS909Context db = new HMS909Context();
     
        public ActionResult Index()
        {
             string query =  "select company as englishName , aname as arabicName, ID, mobile, phone, caseNb as recordNumber, id_no as natID from [hms909].[dbo].[Cust]";

            var list = db.Database.SqlQuery<CustomerList>(query);



            return View(list.ToList());
        }

        public ActionResult Search(String str)
        {
            if(str != null)
            {
                string query = "select company as englishName , aname as arabicName, ID, mobile, phone, caseNb as recordNumber, id_no as natID from [hms909].[dbo].[Cust] where company like '%" + str + "%' or aname like '%" + str + "%' or mobile like '%" + str + "%' or  phone like '%" + str + "%' or caseNb like '%" + str + "%' or  id_no like '%" + str + "%'";

                var list = db.Database.SqlQuery<CustomerList>(query);
                return View(list);

            }
            return View();


 
        }
        //
        // GET: /Customers/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Customers/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Customers/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Customers/Edit/5

        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Customers/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Customers/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Customers/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
